-
Notifications
You must be signed in to change notification settings - Fork 621
feat(instrumentation-pg): add skipConnectSpans option #3280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(instrumentation-pg): add skipConnectSpans option #3280
Conversation
Add a configuration option to skip creating `pg.connect` and `pg-pool.connect` spans while preserving query spans and pool metrics. This helps reduce trace noise in high-throughput scenarios where connection time is not of interest. - Add `skipConnectSpans?: boolean` to PgInstrumentationConfig - Skip span creation for both client and pool connect operations - Still set up event listeners for pool metrics when skipping spans - Add tests for new option - Update README with new option documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
can you also add a changelog for this? https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/packages/instrumentation-pg/CHANGELOG.md |
maryliag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a name suggestion, following the name convention we use in other instrumentations: skip for internal functions, and ignore on user facing configuration (e.g. ignoreResolveSpans)
| | `responseHook` | `PgInstrumentationExecutionResponseHook` (function) | Function for adding custom span attributes from db response | | ||
| | `requireParentSpan` | `boolean` | If true, requires a parent span to create new spans (default false) | | ||
| | `addSqlCommenterCommentToQueries` | `boolean` | If true, adds [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) specification compliant comment to queries with tracing context (default false). _NOTE: A comment will not be added to queries that already contain `--` or `/* ... */` in them, even if these are not actually part of comments_ | | ||
| | `skipConnectSpans` | `boolean` | If true, `pg.connect` and `pg-pool.connect` spans will not be created. Query spans and pool metrics are still recorded (default false) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| | `skipConnectSpans` | `boolean` | If true, `pg.connect` and `pg-pool.connect` spans will not be created. Query spans and pool metrics are still recorded (default false) | | |
| | `ignoreConnectSpans` | `boolean` | If true, `pg.connect` and `pg-pool.connect` spans will not be created. Query spans and pool metrics are still recorded (default false) | |
| if (utils.shouldSkipInstrumentation(plugin.getConfig())) { | ||
| const config = plugin.getConfig(); | ||
|
|
||
| if (utils.shouldSkipInstrumentation(config) || config.skipConnectSpans) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (utils.shouldSkipInstrumentation(config) || config.skipConnectSpans) { | |
| if (utils.shouldSkipInstrumentation(config) || config.ignoreConnectSpans) { |
| // Still set up event listeners for metrics even when skipping spans | ||
| plugin._setPoolConnectEventListeners(this); | ||
|
|
||
| if (config.skipConnectSpans) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (config.skipConnectSpans) { | |
| if (config.ignoreConnectSpans) { |
| * | ||
| * @default false | ||
| */ | ||
| skipConnectSpans?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| skipConnectSpans?: boolean; | |
| ignoreConnectSpans?: boolean; |
| assert.strictEqual(spans.length, 0); | ||
| }); | ||
|
|
||
| it('should not create connect spans when skipConnectSpans=true', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| it('should not create connect spans when skipConnectSpans=true', async () => { | |
| it('should not create connect spans when ignoreConnectSpans=true', async () => { |
| it('should not create connect spans when skipConnectSpans=true', async () => { | ||
| const newPool = new pgPool(CONFIG); | ||
| create({ | ||
| skipConnectSpans: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| skipConnectSpans: true, | |
| ignoreConnectSpans: true, |
| assert.ok(querySpans.length > 0, 'Expected query spans to be created'); | ||
| }); | ||
|
|
||
| it('should still record pool metrics when skipConnectSpans=true', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| it('should still record pool metrics when skipConnectSpans=true', async () => { | |
| it('should still record pool metrics when ignoreConnectSpans=true', async () => { |
| const metricReader = testUtils.initMeterProvider(instrumentation); | ||
| const newPool = new pgPool(CONFIG); | ||
| create({ | ||
| skipConnectSpans: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| skipConnectSpans: true, | |
| ignoreConnectSpans: true, |
Summary
skipConnectSpansconfiguration option to skip creatingpg.connectandpg-pool.connectspansBackground
The
pg.connectandpg-pool.connectspans measure connection time but provide limited actionable insight in many scenarios:Changes
skipConnectSpans?: booleantoPgInstrumentationConfig(defaultfalse)_getClientConnectPatch()and_getPoolConnectPatch()when enabled_setPoolConnectEventListeners()to preserve pool metricsTest plan
skipConnectSpans=trueverifying no connect spans are created🤖 Generated with Claude Code